package com.aijk.ehm.api;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.exception.ErrorCodeException;
import com.aijk.commons.mijo.utils.PojoUtil;
import com.aijk.ehm.model.EhmCompany;
import com.aijk.ehm.model.SemHeight;
import com.aijk.ehm.model.dto.EhmCompanyDto;
import com.aijk.ehm.model.qo.EhmCompanyQo;
import com.aijk.ehm.model.vo.EhmCompanyVo;
import com.aijk.ehm.model.vo.SemHeightVo;
import com.aijk.ehm.service.EhmCompanyService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("ehmCompanyApiImpl")
@Transactional
public class EhmCompanyApiImpl implements EhmCompanyApi {
    private static Logger logger = LoggerFactory.getLogger(EhmCompanyApiImpl.class);

    @Autowired
    private EhmCompanyService service;

    @Override
    public Long save(EhmCompanyDto bean) throws ErrorCodeException {
        service.save(bean);
        return bean.getId();
    }

    @Override
    public void update(EhmCompanyDto bean) throws ErrorCodeException {
        service.update(bean);
    }

    @Override
    public EhmCompanyVo findOne(Long id) throws ErrorCodeException {
        return PojoUtil.convert(service.findOne(id) ,EhmCompanyVo.class );
    }

    @Override
    public List<EhmCompanyVo> list(EhmCompanyQo qo) {
        return PojoUtil.convert(service.find(qo) , EhmCompanyVo.class) ;
    }

    @Override
    public void deleteById(Long id) throws ErrorCodeException {
        service.delete(id);
    }

    @Override
    public int count(EhmCompanyQo qo) {
        return service.count(qo);
    }

    @Override
    public PageInfo<EhmCompanyVo> page(EhmCompanyQo qo) {
        PagingRequest pagingRequest = new PagingRequest(qo.getPageNo().intValue(), qo.getPageSize().intValue());
        PageInfo<EhmCompany> pagelist = service.page(pagingRequest,qo);
        PageInfo<EhmCompanyVo> pagelistvo = PojoUtil.convert(pagelist, PageInfo.class);
        List<EhmCompany> list = pagelist.getList();
        List<EhmCompanyVo> listvo = PojoUtil.convert(list, EhmCompanyVo.class);
        pagelistvo.setList(listvo);
        return pagelistvo;
    }
}